package com.example.elasticsearch.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Range;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.UUID;

/**
 * <pre>
 * 功能描述：
 * </pre>
 *
 * @author: 李明杰
 * @date: 2022/7/22 16:10
 */
@Document(indexName = "presidents2")
@Data
@AllArgsConstructor
@RequiredArgsConstructor(staticName = "of")//配合@NonNull一起用
public class President2 {
    @Id
    private String id;
    @NonNull
    @Field(type = FieldType.Text)
    private String name;
    @NonNull
    @Field(type = FieldType.Integer_Range)
    private Range<Integer> term;

    public static President2 of(String name, Integer from, Integer to) {
        return new President2(UUID.randomUUID().toString(), name, Range.closed(from, to));
    }


}